Namespace("sketch.ui.iphone");

(function(fwk, ui) {
    ui.iphone.Tabbar = klass(ui.common.StackPanel, {
        __type__: "ui.iphone.Tabbar",

        _constructor: function(){
            this.orientation("horizontal");
            this.width(ui.iphone.SCREEN_WIDTH);
            this.height(ui.iphone.TABBAR_HEIGHT);

            this._backgroundResource = fwk.Resources["tabbar_top"];
            this.dropPositioning("horizontal");
            this.enableGroupLocking(true);
        },
        addItem: function(label, imageSrc, active){
            var item = new ui.iphone.TabbarItem();
            item.label(label);
            item.imageSrc(imageSrc);
            item.active(active);
            this.add(item);
        },
        arrange: function(){
            var childWidth = this.width() / this.children.count();

            this.children.each(function(i, child){
                child.width(childWidth);
                child.performArrange();
            });

            ui.iphone.Tabbar.Super.arrange.call(this);
        },

        drawSelf: function(context){
            var t = this.top(),
                h = this.height(),
                l = this.left(),
                w = this.width();
            context.save();
            context.fillStyle = this._backgroundResource.toBrush(context, 0, t, 0, t + h/2);
            context.fillRect(l, t, w, h/2);
            context.fillStyle = fwk.Brush.Black.cssColor;
            context.fillRect(l, t + h/2, w, h/2);
            context.restore();

            this.SuperKlass.drawSelf.call(this, context);
        }
    });
})(sketch.framework, sketch.ui);